<?php

  class Component {
    public $uuid;
    public $style = array();
    public $width;
    public $height;

    function setBounds($x,$y,$w,$h) {
      $this->setStyle("top",$x . "px");
      $this->setStyle("left",$y . "px");
      $this->setStyle("width",$w . "px");
      $this->setStyle("height",$h . "px");
      $this->width = $w;
      $this->height = $h;
    }

    function setLocation($x,$y) {
      $this->setStyle("top",$x . "px");
      $this->setStyle("left",$y . "px");
    }

    function setStyle($name,$value) {
      $this->style[$name] = $value;
    }

    function getStyle($name) {
      return $this->style[$name];
    }

    function show($id,$html="") {
      echo "if(document.getElementById(\"" . $this->uuid . "\")) document.getElementById(\"mainwindow\").removeChild(document.getElementById(\"" . $this->uuid . "\"));\n";   
      echo "el = document.createElement('div');\n";
      echo "el.setAttribute('id','" . $this->uuid . "');\n";
      echo "el.innerHTML = '" . $html . "';\n";
      foreach($this->style as $name => $value) {
        echo "el.style." . $name . " = '" . $value . "';\n";
      }      
      echo "document.getElementById('" . $id . "').appendChild(el);\n";
    }
    
    function close() { 
        echo "Remove('" . $this->uuid . "');\n";
        echo "if('" . $this->uuid . "' in F) delete F['" . $this->uuid . "'];\n";
    }   
    
    function update($string) {}
    function actionPerformed($action) {}

    function __construct($uuid) {
      $this->uuid = $uuid;
      $this->setStyle("position","absolute");
      $this->setBounds(0,0,100,100);
    }
  }

?>
